﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace RimZombieGirl
{
    class CompRaceGiveHediff: ThingComp
    {
        public CompProperties_RaceGiveHediff Props
        {
            get
            {
                return (CompProperties_RaceGiveHediff)this.props;
            }
        }
        public override void PostSpawnSetup(bool respawningAfterLoad)
        {
            base.PostSpawnSetup(respawningAfterLoad);
            if (parent is Pawn pawn && pawn.health?.hediffSet != default)
            {
                Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(Props.hediffDef);
                if (hediff == null)
                {
                    hediff = HediffMaker.MakeHediff(Props.hediffDef, pawn);
                    hediff.Severity = Props.severityInit;
                    pawn.health.AddHediff(hediff);
                }
                if (hediff != null && Props.duration > 0f)
                {
                    HediffComp_Disappears hediffComp_Disappears = hediff.TryGetComp<HediffComp_Disappears>();
                    if (hediffComp_Disappears != null)
                    {
                        hediffComp_Disappears.ticksToDisappear = Props.duration;
                    }
                }
            }
        }
    }
}
